package algorithms;

import org.springframework.boot.web.servlet.server.Session;

import javax.servlet.http.Cookie;

/**
 * @功能
 * @创建时间 2020/5/17
 */
public class Code02 {

    public static int way1(int[] arr){
        int N = arr.length;
        if(arr[N -1] != 0){
            return process1(arr, N - 1,arr[N - 1],2);
        }else {
            int ways = 0;
            for (int v =1;v < 201; v++){
                ways += process1(arr,N - 1,v,2);
            }
            return ways;
        }
    }

    public static int process1(int[] arr, int i, int v, int s) {
        if(i == 0){
            return ((s == 0 || s == 1) && (arr[i] == 0 || v == arr[i])) ? 1 : 0;
        }
        if(arr[i] !=0 && v !=arr[i]){
            return 0;
        }
        int ways = 0;
        if(s == 0 || s ==1) {
            for (int pre = 1; pre < 201; pre++) {
                ways += process1(arr, i - 1, pre, pre < v ? 0 : (pre == v ? 1 : 2));
            }
        }else {
            for(int pre = v;pre < 201; pre++){
                ways += process1(arr, i - 1,pre,pre < v ? 0 :(pre == v ? 1 : 2));
            }
        }
        return ways;
    }
}
